package nccloud.web.gl.voucher.action;

import nc.vo.gl.pubvoucher.VoucherVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.json.JsonFactory;
import nccloud.pubitf.gl.lightgl.voucher.IXiaXinVoucherExtService;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

public class AdjustVoucherNoAction implements ICommonAction  {
    @Override
    public Object doAction(IRequest request) {
        String json = request.read();
        Map<String,Object> map = (Map) JsonFactory.create().fromJson(json, Map.class);
        if (map == null) {
            return null;
        }
        String adjustVoucherNo = (String)map.get("adjustVoucherNo");
        String currentVoucherPK = (String)map.get("currentVoucherPK");
        if(StringUtils.isEmpty(adjustVoucherNo)||StringUtils.isEmpty(currentVoucherPK)){
            return  null;
        }
        VoucherVO voucher =new VoucherVO();
        voucher.setPk_voucher(currentVoucherPK);
        voucher.setNo(Integer.valueOf(adjustVoucherNo));
        try {
            ServiceLocator.find(IXiaXinVoucherExtService.class).adjustVoucherNo(voucher);
        } catch (BusinessException e) {
            ExceptionUtils.wrappBusinessException(e.getMessage());
        }
        return null;
    }
}
